package com.wutong.authority_server.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wutong.authority_server.entity.User;
import com.wutong.authority_server.service.UserService;
import com.wutong.common_server.result.Response;
import com.wutong.common_server.utils.ResponseUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @PreAuthorize("hasRole('admin')")
    @GetMapping("/getUsers")
    @ApiOperation("分页查询所有用户")
    public Response getUsers(){

        Page<User> page = new Page<>();
        page.setCurrent(1);
        page.setSize(10);
        Page<User> userPage = userService.page(page);
        return ResponseUtil.success(userPage);
    }
    @PreAuthorize("hasAuthority('user:addUser')")
    @GetMapping("/addUser")
    @ApiOperation("分页查询所有用户")
    public Response addUser(){

        return ResponseUtil.success("addUser");
    }
}
